﻿using System;
using System.Data;
using System.Data.Objects;
using System.Globalization;
using EstateNuke.Data.Properties;

namespace EstateNuke.Data
{
    public partial class LargeOrderEngagedContractAlert : IAlert
    {
        #region Fileds & Properties

        /// <summary>
        /// </summary>
        public string Name
        {
            get
            {
                if (!AlertTypeReference.IsLoaded)
                {
                    AlertTypeReference.Load(MergeOption.PreserveChanges);
                }
                return string.Format("{0}提醒", AlertType.Name);
            }
        }

        /// <summary>
        /// </summary>
        public string Description
        {
            get
            {
                if (!AlertTypeReference.IsLoaded)
                {
                    AlertTypeReference.Load(MergeOption.PreserveChanges);
                }
                if (!LargeOrderReference.IsLoaded)
                {
                    LargeOrderReference.Load(MergeOption.PreserveChanges);
                }
                return string.Format(AlertType.DescriptionTemplate, LargeOrder.EngagedContractDate.ToString("yyyy年MM月dd日"));
            }
        }

        #endregion

        #region Set Processed

        /// <summary>
        /// </summary>
        /// <param name = "processedByUser"></param>
        /// <param name = "modifiedUser"></param>
        public void SetProcessed(User processedByUser, User modifiedUser)
        {
            if (processedByUser == null)
            {
                throw new ArgumentNullException("processedByUser");
            }
            if (modifiedUser == null)
            {
                throw new ArgumentNullException("modifiedUser");
            }
            Processed = true;
            ProcessedDate = DateTime.Now;
            ProcessedByUser = processedByUser;
            ModifiedDate = DateTime.Now;
            ModifiedByUser = modifiedUser;
        }

        #endregion

        #region Ensure

        /// <summary>
        /// </summary>
        public void Ensure()
        {
        }

        #endregion

        #region Delete

        /// <summary>
        /// </summary>
        public void Delete(User modifiedUser)
        {
            if (modifiedUser == null)
            {
                throw new ArgumentNullException("modifiedUser");
            }
            IsDeleted = true;
            ModifiedDate = DateTime.Now;
            ModifiedByUser = modifiedUser;
        }

        /// <summary>
        /// </summary>
        public void CancelDelete(User modifiedUser)
        {
            if (modifiedUser == null)
            {
                throw new ArgumentNullException("modifiedUser");
            }
            IsDeleted = false;
            ModifiedDate = DateTime.Now;
            ModifiedByUser = modifiedUser;
        }

        #endregion
    }
}